moduleApp.controller("OrderController",function($rootScope,$scope,$location,$http,$interval){
    $scope.user = {};
    var url = window.location.href.split("?")[1];
    url = url.split('&');
    $scope.paramsObj = {};
    for(var i = 0, iLen = url.length; i < iLen; i++){
        var param = url[i].split('=');
        $scope.paramsObj[param[0]] = param[1];
    }
    $http({
        method  : 'POST',
        url     : $rootScope.basePath+'order/get_product_name.do',
        data    : $.param({
            "orderNo":$scope.paramsObj.orderNo
        }),
        dataType: 'json',
        headers : {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
        .success(function(data) {
            if (data.status == 0) {
                $scope.paramsObj.name=data.data;
            }
            else {
                alert(data.msg)
            }
        });
    $http({
        method  : 'POST',
        url     : $rootScope.basePath+'order/pay.do',
        data    : $.param({
            "orderNo":$scope.paramsObj.orderNo
        }),
        dataType: 'json',
        headers : {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
        .success(function(data) {
            if (data.status == 0) {
                $scope.verifyCode=data.data.qrUrl;

            }
            else {
                alert(data.msg)
            }
        });
    $scope.orderResult=false;
    $scope.$watch('verifyCode', function(){
        if($scope.verifyCode){
            $scope.const=0;
            var stop = $interval(function(){
                $scope.const++;
                $http({
                    method  : 'POST',
                    url     : $rootScope.basePath+'order/query_order_pay_status.do',
                    data    : $.param({
                        "orderNo":$scope.paramsObj.orderNo
                    }),
                    dataType: 'json',
                    headers : {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                    .success(function(data) {
                        if (data.status == 0) {
                            if(data.data==true){
                                $scope.orderResult=true;
                                $interval.cancel(stop)
                            }
                        }
                        else {
                            alert(data.msg)
                        }
                  });

            }, 1000);
            if($scope.const>=180){
                $interval.cancel(stop)
            }

        }
    });
})
